<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        .center {
            width: 50%;
            min-height: 700px;
            background-color: coral;
            margin: 0 auto;
        }

        .left {
            width: 20%;
            min-height: 700px;
            background-color: #ff0000;
            position: absolute;
            left: 0;
            top: 0;

        }

        .right {
            width: 20%;
            min-height: 700px;
            background-color: #ff0000;
            position: absolute;
            right: 0;
            top: 0;
        }
    </style>
</head>
<body>
<div class="ui">
    <div class="center"></div>
    <div class="left"></div>
    <div class="right"></div>
</div>
</body>

<script type="text/javascript">

    var press_id = "";-
    $(document).ready(function () {
        press_id = getCookie("press_id");
        if (press_id != null && press_id != "") {
            var url = "user/presslogin?key=" + new Date();
            $.post(url, {"press_id": press_id, "power": 5, "password": $.md5("666666")}, function (data) {
                if (data != null) {
                    data = $.parseJSON(data);
                    if (data.success) {
                        location.href = "page/stat/index.jsp";
                    } else {
                        $("#message").html(data.message);
                        $("#message").show();
                    }
                }
            });
        }
        $("#verifycode").val("");
        $("#sendcode").removeAttr("disabled");
        $("#login").click(function () {
            login();
        });
        $("#sendcode").click(function () {
            sendcode();
        });
    });

    var vcode = "";
    var press_name = "";
    function sendcode() {
        var phonenume = $('#phone').val();
        if (phonenume == null || phonenume == "") {
            $("#message").html("请输入手机号");
            $("#message").show();
            $("#phone").select();
            return;
        } else {
            settimeOut();
            var url = "user/phoneVerify?key=" + new Date();
            $.getJSON(url, {"phone": phonenume}, function (data) {
                if (data != null) {
                    if (data.success) {
                        vcode = data.vcode;
                        press_id = data.pressinfo.id;
                        press_name = data.pressinfo.username;

                    } else {
                        $("#message").html(data.message);
                        $("#message").show();
                    }
                }
            });
        }
    }

    var countdown = 60;
    function settimeOut() {
        if (countdown == 0) {
            $("#sendcode").removeAttr("disabled");
            $("#sendcode").html("发送验证码");
            countdown = 60;
            return;
        } else {
            $("#sendcode").attr("disabled", true);
            $("#sendcode").html("重新发送(" + countdown + ")");
            countdown--;
            setTimeout(function () {
                        settimeOut()
                    }
                    , 1000)
        }
    }

    function login() {
        var verifycode = $("#verifycode").val();
        var phonenume = $('#phone').val();
        if (phonenume == null || phonenume == "") {
            $("#message").html("请输入手机号");
            $("#message").show();
            $("#phone").select();
            return;
        }
        if (verifycode == null || verifycode == "") {
            $("#message").html("请输入短信验证码");
            $("#message").show();
            $("#verifycode").select();
            return;
        }
        if (verifycode != vcode) {
            $("#message").html("短信验证码错误");
            $("#message").show();
            $("#verifycode").select();
            return;
        }

        var url = "user/presslogin?key=" + new Date();
        $.post(url, {
            "phone": phonenume,
            "username": press_name,
            "press_id": press_id,
            "power": 5,
            "password": $.md5("666666")
        }, function (data) {
            if (data != null) {
                data = $.parseJSON(data);
                if (data.success) {
                    //记住登录信息
                    addCookie("press_id", press_id, 720);
                    location.href = "page/stat/index.jsp";
                } else {
                    $("#message").html(data.message);
                    $("#message").show();
                }
            }
        });


    }

</script>


</html>